package cn.imvc.app.controllers.member;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;

import cn.imvc.app.entities.Member;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.app.models.MemberModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.HttpContext;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

/**
 * 
 * @author wujx
 * @time 2016年7月20日
 *
 */
public class MemberControllerImpl implements MemberController {
	static Logger logger = Logger.getLogger(MemberControllerImpl.class);
	
	@Autowired
	private MemberModel memberModel;
	private ViewRequest viewRequest;
	private Page<Member> page;
	private Member member;
	private int id;
	
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		page = memberModel.findAll(viewRequest);
		return "member/index";
	}

	public String detail() {
		member = memberModel.getOne(id);
		return "member/detail";
	}
	
	public String show() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public String editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	public String create() {
		// TODO Auto-generated method stub
		return null;
	}

	public String edit() {
		member = memberModel.getOne(id);
		return "member/edit";
	}

	public String update() { 
		memberModel.update(member,id);
		loggingModel.info(logger,"更改会员信息："+id);
		return Render.json(new DialogBean("200", "修改成功！","","closeCurrent"));
	}
	
	/**
	 *  提供会员选择接口
	 */
	public String dialog(){
		page = memberModel.findAll(viewRequest);
		return "member/dialog";
	}
	
	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroyBatch() {
		// TODO Auto-generated method stub
		return null;
	}

	//重置登陆密码
	public String resetPassword(){
		memberModel.updateResetPassword(id);
		loggingModel.info(logger,"重置会员登录密码："+id);
		
		return Render.json(new DialogBean("200", "登陆密码修改成功，默认密码:123456。","member"));
	}
	
	// 重置支付密码
	public String resetPaypwd() {
		memberModel.updateResetPaypwd(id);
		loggingModel.info(logger,"重置会员支付密码："+id);
		return Render.json(new DialogBean("200", "支付密码修改成功，默认密码:123456。", "member"));
	}
	
	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public Page<Member> getPage() {
		return page;
	}

	public void setPage(Page<Member> page) {
		this.page = page;
	}



}
